let app = getApp();
Page({
  data: {
    page:1,
    parmas:null,
    shareList:[],
    pageNext:true,
    showOrder:false,
    list:false,
    user:null
  },

  onLoad: function (e) {
    var token = wx.getStorageSync('ACCESS_TOKEN');
    if(token){
      this.data.token = token;
      this.setData({
        parmas:e
      })
      this.data._api_live = app.args.api.siteinfo.sitelive;
      this.getShareList(e.id)
    }else {
      app.args.page.onLoad(this, e);
    }
  },

  getShareList(id){
    let t = this,d=t.data;
    app.args.request({
      url: d._api_live + 'live/myShareInfoList',
      data:{
        hosId:app.args.api.siteinfo.hosId2,
        liveId: id,
        page:d.page,
        items:20,
      },
      success(e){
        wx.stopPullDownRefresh();
        if(e.data.length){
          d.page++;
          d.shareList.push(...e.data);
          t.setData({
            shareList:d.shareList,
            pageNext:true
          })
          t.getShareList(id)
        }else {
          d.page--;
          t.setData({
            pageNext:false
          })
        }
      }
    })
  },

  setShow(){
    this.setData({showOrder:!this.data.showOrder});
  },
  showOrder(e){
    let t = this,d=t.data;
    t.setData({
      showOrder:!t.data.showOrder,
      user:e.currentTarget.dataset.id
    })
    console.log(e.currentTarget.dataset.id);
    /* wx.showLoading({title: '加载中'})
    app.args.request({
      url: d._api_live + '/live/getInviteCustomerOrderList',
      data:{
        hosId:app.args.api.siteinfo.hosId2,
        liveId: d.parmas.id,
        openid:e.currentTarget.dataset.id
      },
      success(result){
        console.log(result)
        wx.hideLoading()
        if(result.code == 0 && result.msg == "success") {
          if(result.data.length == 0) {
            wx.showToast({title: '无记录',icon: 'none',duration: 2000})
          }else{
            t.setData({
              showOrder:!t.data.showOrder,
              list:Object.assign(result,e.currentTarget.dataset)
            })
          }
        }
      }
    }) */
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let d = this.data;
    d.shareList.length=0;
    d.page=1;
    this.getShareList(d.parmas.id);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let d = this.data;
    if(!d.pageNext && d.shareList.length>19) return;
    d.pageNext = false;
    this.getShareList(d.parmas.id);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let d = this.data
    return {
      title:d.parmas.title,
      path:'/cheng/pages/live1/live1?id='+d.parmas.id+'&oriToken='+d.token+'&referee_id='+wx.getStorageSync('user_id'),
      imageUrl:d.parmas.img
    }
  }
})